//
//  XLTalkThemeSheetView.m
//  XiangLove
//
//  Created by 李传坤 on 2018/6/5.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLTalkThemeSheetView.h"
#import "XLTalkThemeCell.h"
#import <ReactiveCocoa.h>

@interface XLTalkThemeSheetView()<UITableViewDelegate,UITableViewDataSource>{
    
}
@property (nonatomic, strong) UITableView     *tableView;

@end

@implementation XLTalkThemeSheetView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addViews];
    }
    return self;
}

- (void)addViews{//////
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 0, ScreenWidth, SCREEN_HEIGHT);
    [backButton setTitle:@"" forState:UIControlStateNormal];
    backButton.backgroundColor = RGBA_HEX(0x000000, 0.2);
    [backButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:backButton];
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth -180, ScreenHeight -250, 120, 165)];
    image.tag = 1000;
    image.backgroundColor = kClearColor;
    image.image = [UIImage imageNamed:@"cmmon_bg_huati"];
    image.hidden = YES;
    [self addSubview:image];
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.rowHeight = 44;
    _tableView.frame = CGRectMake(ScreenWidth -180, ScreenHeight -250, 120, 160);
    _tableView.tableFooterView = [UIView new];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.layer.cornerRadius = 5;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.separatorColor = [UIColor clearColor];
    [_tableView registerClass:[XLTalkThemeCell class] forCellReuseIdentifier:NSStringFromClass([XLTalkThemeCell class])];
    [self addSubview:_tableView];
   
}
- (void)getChatThemeList{
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    XLTalkThemeCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XLTalkThemeCell class]) forIndexPath:indexPath];
    cell.tittleLabel.text = [_dataArray[indexPath.row] objectForKey:@"TypeName"];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    _block(_dataArray[indexPath.row][@"Id"]);
}
- (void)getChatThemeListReloadData1:(NSString *)callID{
    [[[XLHTTPSessionManager sharedManager] XLV2GET:@"/api/v2/VideoChat/GetTopicTypes" parameters:@{@"callId":callID} resultClass:nil]subscribeNext:^(id x) {
        _dataArray = x;
        [_tableView reloadData];
        _tableView.frame = CGRectMake(ScreenWidth -180, ScreenHeight -(44 * _dataArray.count + 90), 120, 44 * _dataArray.count + 5);
        UIImageView * imageView = (UIImageView *)[self viewWithTag:1000];
        imageView.hidden = NO;
        imageView.frame = CGRectMake(ScreenWidth -180, ScreenHeight -(44 * _dataArray.count + 85), 120, 44 * _dataArray.count + 5);
    } error:^(NSError *error) {
        
    }];
}
- (void)show{
    [[[[UIApplication sharedApplication]delegate]window]addSubview:self];
}
- (void)dismiss{
    [UIView animateWithDuration:0.3
                          delay:0.0
                        options: UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         self.alpha = 0;
                     }
                     completion:^(BOOL finished){
                         [self removeFromSuperview];
                     }];
}
@end
